package com.eerl.pdev.werl.impl;

import com.eerl.pdev.exception.ErlTypeInitUnSupportRuntimeException;
import lombok.Getter;
import lombok.ToString;

import java.lang.reflect.Array;

@Getter
@ToString
public class ErlangType {

    public static final int ERLANG_TYPE_ATOM = 1;
    public static final int ERLANG_TYPE_NUMBER = 2;
    public static final int ERLANG_TYPE_BOOL = 3;
    public static final int ERLANG_TYPE_STRING = 4;

    public static final int ERLANG_TYPE_LIST = 10;
    public static final int ERLANG_TYPE_TUPLE = 11;

    public static final Object EMPTY_VAL = "";

    private Object value;
    private int type;

    public ErlangType(Object value, int type) {
        if ((type == ERLANG_TYPE_LIST || type == ERLANG_TYPE_TUPLE) && !(value instanceof Array)) {
            throw new ErlTypeInitUnSupportRuntimeException();
        }
        if (!(value instanceof String)) {
            throw new ErlTypeInitUnSupportRuntimeException();
        }
        this.value = value;
        this.type = type;
    }

}
